﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;
using Message;

namespace ServerBattle
{
    internal class BattleReadyHandler : MessageHandler<BattleReadyRequest, BattleReadyResponse>
    {
        protected override async ETTask Handle(ISession session, BattleReadyRequest request, BattleReadyResponse response, Func<ETTask> completed)
        {
            var dataCom = session.Entity.GetOrAddComponent<PlayerDataComponent>();
            dataCom.userId = request.userId;

            new OnPlayerConnectRoom(session).Publish();

            await completed();

            session.Register(dataCom.userId);
        }
    }

    public class PlayerDataComponent : EntityComponent
    {
        public uint userId;
    }

    public struct OnPlayerConnectRoom : IEventData
    {
        public ISession session;

        public OnPlayerConnectRoom(ISession session)
        {
            this.session = session;
        }
    }
}